const path = require('path');
const analyzer = require('webpack-bundle-analyzer');
// const nodeServer = require('./node');

const resolve = dir => path.join(__dirname, dir);

// 基础路径 注意发布之前要先修改这里
// let baseUrl = "./";

// nodeServer(baseUrl);

module.exports = {
  // 根据你的实际情况更改这里
  publicPath: '/',
  lintOnSave: true,

  devServer: {
    publicPath: '/' // 和 baseUrl 保持一致
  },

  productionSourceMap: false,

  chainWebpack: config => {
    config.plugins.delete('prefetch');
    //忽略的打包文件
    // config.externals({
    //   vue: "Vue",
    //   "vue-router": "VueRouter",
    //   vuex: "Vuex",
    //   axios: "axios",
    //   "element-ui": "ELEMENT",
    //   // my: 'my',
    // });
    const entry = config.entry("app");
    entry.add("babel-polyfill").end();
    entry.add("classlist-polyfill").end();
    config.resolve.alias.set("@", resolve("src"));
    if(process.env.NODE_ENV === 'production' && !!process.env.npm_config_analyzer == true){
      config
        .plugin('webpack-bundle-analyzer')
        .use(analyzer.BundleAnalyzerPlugin)
    }
  },

  configureWebpack: config => {
    if(process.env.NODE_ENV === 'production'){
      config.optimization.minimizer[0].options.terserOptions.compress.drop_console = true;
    }
  },

  css: {
    sourceMap: true,
    loaderOptions: {
      stylus: {
        'resolve url': true,
        'import': []
      }
    }
  },

  transpileDependencies: [/\bavue-plugin-transfer\b/, /\bavue-plugin-ueditor\b/],

  //配置转发代理
  // eslint-disable-next-line no-dupe-keys
  devServer: {
    open:true,
    host:"0.0.0.0",
    port:8080,
    https:false,
    proxy: {
      '/api': {
        target: 'https://zwfw.zhumadian.gov.cn:8080',
        changeOrigin: true,
        ws: true,
        pathRewrite: {
          '^/api': '/'
        }
      },
    },
  }
};
